<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据的双向绑定</title>
</head>
<body>

<!--
    双向数据绑定
    v-model       data   ->  view  -> data   数据是双向绑定
    v-bind:value="uname"    数据是单向的绑定    data  -> view
-->
<div id="app">
    <form>
        <p><input type="text" name="username" id="username" v-model="user.uname"  placeholder="请输入用户名"></p>
        <p><input type="text" name="password" id="password" v-model="user.pwd" placeholder="请输入密码"></p>
        <p><input type="text" name="age" id="age" v-model="user.age" placeholder="请输入年龄"></p>
        <p><input type="button" value="立即提交" @click="loginVue"></p>
    </form>
</div>

<script src="../vue.js"></script>

<script>
    const vm = new Vue({
        el: '#app',
        data: {
            // uname:'tom',
            // pwd:'123456',
            // age:20
            user: {
                uname: 'jack',
                pwd: "123456",
                age: 20
            }
        },
        methods: {

            login() {
                //  发送异步请求   表单数据
                let username = document.getElementById("username").value;
                let password = document.getElementById("password").value;
                let age = document.getElementById("age").value;
                console.log("登录");
                console.log(username, password, age)
                //  封装数据
                const user = {username, password, age}
                let userStr = JSON.stringify(user)   //  json 字符串
            },
            loginVue() {
                //  发送异步请求   表单数据
                console.log("登录");
                // console.log(this.uname, this.pwd, this.age)

                console.log(this.user)
            },

            // 编辑用户信息
            edit(id) {
                // 发送异步请求   json  user


            }
        }
    })
</script>

</body>
</html>